package demo15

// 备忘录 设计模式 memento
import "fmt"

type Memento interface{}
// 对外接受数据
type Game struct{
	hp,mp int
}
// 对内存储不公开
type gameMemento struct{
	hp,mp int
}

func NewGame(hp,mp int) *Game{
	return &Game{
		hp:hp,
		mp:mp,
	}
}	
func (g *Game)Play(hp,mp int){
	g.hp += hp
	g.mp += mp 
}
func (g *Game)Save() *gameMemento{
	return &gameMemento{
		hp:g.hp,
		mp:g.mp,
	}
}
func (g *Game)Status(){
	fmt.Println(g.hp,g.mp)
}

func (g *Game)Load(m Memento){
	memento := m.(*gameMemento)
	g.hp =memento.hp
	g.mp =memento.mp
}